package com.lcy.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lcy.reggie.common.Result;
import com.lcy.reggie.entity.Category;
import com.lcy.reggie.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * ======刘春春大帅逼======
 * ******java学习之旅******
 */


/**
 *  分类管理
 */
@RestController
@Slf4j
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;


    /**
     * 新增菜品/套餐分类
     * @param category
     * @return
     */
    @PostMapping
    public Result<String> addCategory(@RequestBody Category category){
        return categoryService.addCategory(category);
    }

    /**
     *  分页
     */
    @GetMapping("/page")
    public Result<Page> pageResult(HttpServletRequest request,Integer page,Integer pageSize){
        return categoryService.pageResult(request,page,pageSize);
    }

    /**
     *  删除分类
     */
    @DeleteMapping
    public Result<String> delete(@RequestParam("ids") Long id){
        return categoryService.delete(id);
    }


    /**
     *  修改功能
     */
    @PutMapping
    public Result<String> update(@RequestBody Category category){
        return categoryService.update(category);
    }


    /**
     * 根据type查询分类数据
     */
    @GetMapping("/list")
    public Result<List<Category>> list(Category category){
        return categoryService.list(category);
    }
}
